// 下载阶段性报告
import {getUserInfo} from "@/utils/format";
import ServiceEnvs from "@/services/ServiceEnvs";
import {request} from "umi";

const baseUrl = ServiceEnvs.baseUrl
export const DownloadApi = () => {

  const userInfo = getUserInfo()
  const api = '/api/download-report'
  const url = baseUrl+api
  const eleLink = document.createElement('a');
  eleLink.style.display = 'none';
  eleLink.href = url;
  document.body.appendChild(eleLink);
  eleLink.click();
  document.body.removeChild(eleLink);
}

export const DownloadByNameApi = (name) => {

  const userInfo = getUserInfo()
  const api = '/api/word-filled-download?filename='+name
  console.log("@api", api)
  const url = baseUrl+api
  const eleLink = document.createElement('a');
  eleLink.style.display = 'none';
  eleLink.href = url;
  document.body.appendChild(eleLink);
  eleLink.click();
  document.body.removeChild(eleLink);


  // const userInfo = getUserInfo()
  // const queryString = new URLSearchParams({filename: name}).toString()
  // console.log(queryString)
  // return request(baseUrl+'/api/word-filled-download', {
  //   method: 'POST',
  //   headers: {
  //     'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
  //     'Authorization': userInfo.token
  //   },
  //   data: queryString,
  // })

}

export const DownloadExcelApi = () => {

  const userInfo = getUserInfo()
  const api = '/api/download-allexcels'
  const url = baseUrl+api
  const eleLink = document.createElement('a');
  eleLink.style.display = 'none';
  eleLink.href = url;
  document.body.appendChild(eleLink);
  eleLink.click();
  document.body.removeChild(eleLink);
}

//下拉菜单
export const ProvinceMenu = () => {
  const userInfo = getUserInfo()
  const api = '/api/govl-query-scdis-handler'
  const url = baseUrl + api

  return request(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Authorization': userInfo.token
    },
  })
}

// 删除项目
export const ProvinceDelete = (fill_id: string, row_id: [], school_descipline: string) => {
  const userInfo = getUserInfo()
  const api = '/api/gov-review-del/delete-school-data'
  const url = baseUrl + api

  return request(url, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json;charset=utf-8',
      'Authorization': userInfo.token
    },
    data: {fill_id, row_id, school_descipline}
  })
}
